package com.tpix.photo;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;

import javax.jdo.annotations.PersistenceCapable;
import javax.persistence.Id;

@PersistenceCapable
public class Photo {
	
	@Id
	private Long id;
	private String title;
	private String caption;
	private String description;
	private String albumName;
	private List<String> tagList;
	private String location;
	private String blobKey;
	private Date date;
	private String user;
	
	public Photo(){
		
	}
	
	public Photo(String title,String caption, String blobKey){
		this.title = title;
		this.caption = caption;
		this.blobKey = blobKey;
		this.user = "default";
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public String getAlbumName() {
		return albumName;
	}

	public void setAlbumName(String albumName) {
		this.albumName = albumName;
	}

	public List<String> getTagList() {
		return tagList;
	}
	/*
	 * takes comma separated String of tags, creates ArrayList of tags
	 */
	public void setTagList(String tagList) {
		// replace newlines with comma
		tagList = tagList.replace("\n", ",");
		tagList = tagList.replace("\r", ",");

		// separate tags on comma
		String [] taglistArray = tagList.split(",");
		
		this.tagList = Arrays.asList(taglistArray);
		// remove leading and trailing spaces from each tag
		ListIterator<String> itr = this.tagList.listIterator();
		while(itr.hasNext()){
			String tag = itr.next();
			itr.set(tag.trim());
		}
	}
	public void setTagList(List<String> tagList) {
		this.tagList = tagList;
	}
	public String getBlobKey() {
		return blobKey;
	}

	public void setBlobKey(String blobKey) {
		this.blobKey = blobKey;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	public String getUser() {
		return this.user;
	}
	public void setUser(String newName) {
		this.user = newName;
	}
	
	
	
	
}
